<template >
  <div class="add_con_form tl">
    <el-dialog
      :close-on-click-modal="false"
      title="编辑充值"
      :modal-append-to-body="false"
      :visible.sync="visible"
      :show="show"
      :before-close="closeDialog"
      @close="$emit('update:show',false)"
      class="tl size_13"
      width="800px"
    >
      <el-form
        :model="data"
        v-loading="loading"
        :rules="dataYZ"
        ref="data"
        class="mar_top"
        label-width="120px"
      >
        <el-form-item label="订单号" prop="oid">
          <el-col :span="12">
            <el-input
              placeholder="请输入奖励名称"
              v-model="data.oid"
              :disabled="true"
              clearable
            ></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="状态">
          <el-col :span="24" v-if="status=='0' || status=='2'">
            <el-radio v-model="data.status" label="0">未支付</el-radio>
            <el-radio v-model="data.status" label="2">支付中</el-radio>
            <el-radio v-model="data.status" label="1">已支付</el-radio>
            <el-radio v-model="data.status" label="3">支付失败</el-radio>
          </el-col>
          <el-col :span="24" v-else>
            <el-radio v-model="data.status" disabled label="0">未支付</el-radio>
            <el-radio v-model="data.status" disabled label="2">支付中</el-radio>
            <el-radio v-model="data.status" disabled label="1">已支付</el-radio>
            <el-radio v-model="data.status" disabled label="3">支付失败</el-radio>
          </el-col>
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-col :span="12">
            <el-input placeholder="请输入备注" v-model="data.remark" clearable></el-input>
          </el-col>
        </el-form-item>

        <div class="mar_bottom_15">
          <span class="sizeColor size_13 sp_style"></span>
          <el-button
            :loading="$store.state.isLoading"
            size="medium"
            type="primary"
            @click.prevent="addUpdate('data')"
          >确定</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>


<style lang="less" scoped>
</style>

<script>
export default {
  data() {
    var checkTitle = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("标题不能为空"));
      } else {
        callback();
      }
    };

    return {
      value: "",
      data: {
        id: "",
        adminId: "",
        status: "0",
        remark: ""
      },
      status: "2",
      loading: false,
      dataYZ: {
        title: [{ validator: checkTitle, trigger: "blur" }]
      },
      visible: this.show
    };
  },
  props: {
    show: Boolean,
    rechargeId: String
  },
  methods: {
    closeDialog() {
      //this.$refs['data'].resetFields();
      this.visible = false;
    },
    getDetails(id) {
      var data = {};
      data["id"] = id;
      this.loading = true;
      this.$api.getUser.getRechargeInfo(data).then(res => {
        this.data = res.data.result;
        this.status = res.data.result.status;
        this.radio = res.data.result.status;
        this.loading = false;
      });
    },
    addUpdate(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          var params = {};
          params["id"] = this.data.id;
          params["admin_id"] = this.data.adminId;
          params["status"] = this.data.status;
          params["remark"] = this.data.remark;
          this.$api.getUser.rechargeUpdate(params).then(res => {
            console.log(res);
            if (res.data.code == 200 && res.data.result != null) {
              this.$emit("parent", "这里刷新父页面");
              this.$fnc.alertSuccess({ text: "编辑成功" }); //成功弹出框
              this.visible = false;
            } else {
              this.$fnc.alertError(res.data.result); //失败弹出框
            }
          });
        }
      });
    }
  },
  watch: {
    show() {
      console.log(this.show);
      this.visible = this.show;
    },
    rechargeId(id) {
      console.log("id", id);
      this.getDetails(id);
    }
  },
  mounted() {
    //this.getDetails(this.$route.query.id);
  },
  created() {}
};
</script>
